//
//  HJZKeyBoardToolBar.m
//  HJZWeiBo
//
//  Created by 蒋晨成 on 16/6/4.
//  Copyright © 2016年 蒋晨成. All rights reserved.
//

#import "HJZKeyBoardToolBar.h"
#import "UIImage+Extend.h"

#define HJZKeyBoardToolBarPaddings ((kWidth - 100 - 20) / 4)
#define HJZKeyBoardToolBarXPaddings 10
#define HJZKeyBoardToolBarWidth 20


@interface HJZKeyBoardToolBar ()



@end

@implementation HJZKeyBoardToolBar

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
/**
 *  添加两条线
 */
        UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 1)];
        topLine.backgroundColor = [UIColor grayColor];
        [self addSubview:topLine];
        UIView *bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0, frame.size.height - 1, kWidth, 1)];
        bottomLine.backgroundColor = [UIColor grayColor];
        [self addSubview:bottomLine];
        
        NSArray *images = @[@"pic.png", @"aiter.png", @"well.png", @"emoji.png", @"plus.png"];
        
        for (int i = 0; i < 5; i++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.tag = 1500 + i;
            [button setBackgroundImage:[UIImage resizedImageWithName:images[i]] forState:UIControlStateNormal];
            button.frame = CGRectMake(HJZKeyBoardToolBarXPaddings + (HJZKeyBoardToolBarWidth + HJZKeyBoardToolBarPaddings) * i, (frame.size.height - 20) / 2, HJZKeyBoardToolBarWidth, 20);
            [button addTarget: self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:button];
        }
        
    
        
        
    }
    return self;

}

- (void)buttonAction:(UIButton *)button {
   
    if (button.tag == 1500) {
       
        if (self.picButtonBlock) {
            self.picButtonBlock();
        }
        
    }else if (button.tag == 1501) {
        
        if (self.aiterButtonBlock) {
            self.aiterButtonBlock();
        }
    
    }else if (button.tag == 1502) {
        
        if (self.topicButtonBlock) {
            self.topicButtonBlock();
        }
        
    }else if (button.tag == 1503) {
    
        if (self.emojiButtonBlock) {
            self.emojiButtonBlock();
        }
        
    }else {
    
        if (self.addButtonBlock) {
            self.addButtonBlock();
        }
    }
    
}
@end
